var base_url ='http://sfadmin.wenlongli.com/';

function getMsgBox( data ) {
    var type = arguments[1] ? arguments[1] : 'info';
    var pub = $('#public-pages .alert-'+type),
        page = pub.clone(),
        message = '';
    $.each(data, function (k,v) {
        message += v + '<br/>';
    });
    page.find('.content').html( message );
    return page;
}

function popupBox( page ) {
    var callback = arguments[1] ? arguments[1] : '';

    layer.open({
        title:false,
        closeBtn: 0,
        type: 1,
        // area: ['50%', '70%'],
        content: page[0].outerHTML, //这里content是一个普通的String
        success: function(layero, index){
            $(layero).css('border-radius', '.25rem');
            $(layero).find('.alert .close').on('click', function (event) {
                layer.close( index );
            });

            if(typeof callback === "function"){
                //调用它，既然我们已经确定了它是可调用的
                callback(layero, index);
            }
        }
    });
}


/*const Toast = Swal.mixin({
    toast: true,
    position: 'top-end',
    showConfirmButton: false,
    timer: 3000
});

//
function Util() {

}

Util.prototype = {
    constructor : Util,
    toast : function () {
        return Swal.mixin({
            toast: true,
            position: 'top-end',
            showConfirmButton: false,
            timer: 3000
        });
    }
};

var util = new Util();*/

$(".doClear").on('click',function () {
    $.ajax({
        url:"http://sfadmin.wenlongli.com/admin/system/cleanCache",
        data:1,
        error:function () {

        },
        success:function ( data ) {
            console.log(data);
            if( data == true ){
                popupBox( getMsgBox( {'success':'更新缓存成功'}, 'success' ) );
                setTimeout(function () {
                    window.location.reload();
                }, 600);
            }else{
                popupBox( getMsgBox( {'danger':'更新缓存失败'}, 'danger' ) );
            }
        }
    });
});
fileImage();
function fileImage() {
    var file = $("input[type='file']");
    var img = file.parents('.mailbox-attachment-info').siblings('.mailbox-attachment-icon').find("img");

    $(file).on("change",function (e) {
        var t = this.files.item(0);
        var url = window.URL.createObjectURL( t );
        $(img).attr("src",url);
    })
}